package com.zimmur.tools;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zimmur.common.PropertiesCommon;

public class HttpSendSms {
	private static Logger log = LoggerFactory.getLogger(HttpSendSms.class);
	
	//行业帐号IP为222.73.117.156，PORT默认为80.
	//营销帐号IP为222.73.117.169，PORT默认为80.
	private static String url;
	private static String account;
	private static String pswd;
	
	static {
		url=PropertiesCommon.getProperty("HTTPSMS.URL");
		account=PropertiesCommon.getProperty("HTTPSMS.USER");
		pswd=PropertiesCommon.getProperty("HTTPSMS.PWD");
	}
	
	public static boolean sendSms(String mobileNo,String msg,boolean needStatus){
		boolean bRet = false;
		try {
			Map<String, Object> map = new HashMap<String,Object>();
			map.put("account", account);
			map.put("pswd", pswd);
			map.put("mobile", mobileNo);
			map.put("needstatus", String.valueOf(needStatus));		
			map.put("msg", msg);
			map.put("extno", "");
			String strRet = HttpClientUtil.doPost(url, map);
			if(!strRet.equals("") && strRet.split(",")[1].equals("0")){
				bRet = true;
			}else{
				log.error("send sms error:"+strRet);
			}
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		
		return bRet;
	}
	
	public static void main(String[] args) {
		String mobileNo="13590122932";
		String msg="您好，您的验证码是8888";
		
		boolean ret=HttpSendSms.sendSms(mobileNo, msg, false);
		System.out.println(ret);
	}
}
